import { ElLoading } from 'element-plus'

const defaultOptions = {
  lock: true,
  text: 'Loading...',
}
export const useFullscreenLoading = (fn, options = {}) => {
  let loadingInstance
  return async (...args) => {
    try {
      loadingInstance = ElLoading.service({ ...defaultOptions, ...options })
      return await fn(...args)
    } finally {
      loadingInstance?.close()
    }
  }
}
